package com.ctshk.rpc.guide.mapper;

import com.ctshk.rpc.guide.entity.GuideCollarScheduling;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.guide.req.GuideCollarSchedulingQueryReq;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 排班管理 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-03
 */
public interface GuideCollarSchedulingMapper extends BaseMapper<GuideCollarScheduling> {


    @Select("<script>"+"select * from t_guide_collar_scheduling where is_deleted = 0 and guide_collar_id = #{req.guideCollarId} " +
            "and DATE_FORMAT(scheduling_date,\"%y-%m-%d\") = DATE_FORMAT(#{localDate},\"%y-%m-%d\") " +
            "<if test=\"req.workTypeId != null\">and work_type_id= #{req.workTypeId} </if> order by working_hours desc"+"</script>")
    List<GuideCollarScheduling> selectListByLocalDateAndCollar(@Param("req") GuideCollarSchedulingQueryReq req, @Param(("localDate")) LocalDate localDate);

    @Update("update t_guide_collar_scheduling set is_deleted = 0 where guide_collar_id = #{guideCollarId} and DATE_FORMAT(scheduling_date,\"%y-%m-%d\") = DATE_FORMAT(#{newDate},\"%y-%m-%d\")")
    void updateByLocalDate(@Param("newDate") LocalDate newDate, @Param("guideCollarId") Long guideCollarId);


}
